package com.bear.cmcc.NetTestHTTP.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.bear.cmcc.NetTestHTTP.R;
import com.bear.cmcc.NetTestHTTP.component.InfoBean;
import com.bear.cmcc.NetTestHTTP.util.MyCommonUtil;

/**
 * 订阅详细
 * 
 * @author jqa
 * 
 */
public class InfoSubDetailActivity extends AbstractActivity {
	private Intent intent;
	private TextView tvTitle, tvAuthorandtime, tvContent;
	InfoBean info;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		loadBottomBar();
		setCloseButton(R.string.top_back, listener);
		setShareButton(listener);
		setTitle(R.string.info_sub_title);
		choseBottomItemIndex(2);
		setContentView(R.layout.layout_infosub_detail);
		init();
	}
	
    @Override
    protected void onStart()
    {
    	choseBottomItemIndex(2);
    	super.onStart();
    }

	/**
	 * 初始化
	 */
	private void init() {
		tvTitle = (TextView) findViewById(R.id.textViewTitle);
		tvAuthorandtime = (TextView) findViewById(R.id.textViewAuthorandtime);
		tvContent = (TextView) findViewById(R.id.textViewContent);
		intent = getIntent();
		info = (InfoBean) intent.getSerializableExtra("info");
		if (info != null) {
			tvTitle.setText(info.getTitle());
			tvAuthorandtime.setText("作者:"+info.getAuther() + "\t" + info.getTime());
			tvContent.setText(info.getContent());
		}
	}

	private OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btn_left:
				finish();
				break;
			case R.id.btn_right:
				MyCommonUtil.share(InfoSubDetailActivity.this,
						getString(R.string.share), setShareData(info));
				break;
			default:
				break;
			}
		}
	};

	/**
	 * 设置分享的信息
	 * 
	 * @return
	 */
	private String setShareData(InfoBean _info) {
		StringBuffer mData = new StringBuffer();
		mData.append("标题:").append(_info.getTitle()).append("\n");
		mData.append("作者:").append(_info.getAuther()).append("\n");
		mData.append("内容:\n").append("\t").append(_info.getContent());
		return mData.toString();
	}
}
